﻿
#region Imports Directives

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Quartz;
using log4net;

#endregion

namespace ScenarioFramework.WorkflowEngine.Events.Jobs
{
    public class SingalJob : ScenarioJob
    {

        public override void Run(Quartz.JobExecutionContext context)
        {
            context.Scheduler.PauseTrigger(context.Trigger.Name, "Scenario");
            System.Console.Out.WriteLine(string.Format("{0} Signal", DateTime.Now.ToLongTimeString()));
            long lProcessId=0;
            WAPI.Response wapiResponse = new WAPI.Response();
            System.Console.Out.WriteLine("Create Process [StartEnd]");
            WAPI.Process.CreateProcessInstance("StartEnd", ref lProcessId, ref wapiResponse);
            if (wapiResponse.iCode == 0)
            {
                System.Console.Out.WriteLine("Process {0} created", lProcessId);
            }
            else
            {
                System.Console.Out.WriteLine("Impossible to create Process");
                context.Scheduler.ResumeTrigger(context.Trigger.Name, "Scenario");
                return;
            }

            WAPI.Process.StartProcessInstance(lProcessId, ref wapiResponse);
            if (wapiResponse.iCode == 0)
            {
                System.Console.Out.WriteLine("Process {0} started", lProcessId);
            }
            else
            {
                System.Console.Out.WriteLine("Impossible to start Process");
                context.Scheduler.ResumeTrigger(context.Trigger.Name, "Scenario");
                return;
            }
            context.Scheduler.DeleteJob(context.JobDetail.Name, "Scenario");
        }

    }
}
